// Copyright (C) 1953-2022 NUDT
// Verilog module name - local_management_proxy
// Version: V3.4.0.20220228
// Created:
//         by - fenglin
////////////////////////////////////////////////////////////////////////////
// Description:
//         hardware control point
///////////////////////////////////////////////////////////////////////////
`timescale 1ns/1ps

module local_management_proxy
(
        i_clk             ,
        i_rst_n           ,  

        o_tsn_or_tte      ,
        i_sync_ok         ,
        ov_local_id       , 
        iv_tss_ver        ,
        o_rc_rxenable     ,
        o_st_rxenable     ,
        iv_master_port       ,
        iv_port_ptp_enabled  ,        
                
        o_wr_tsc          ,        
        ov_wdata_tsc      ,      
        ov_addr_tsc       ,          
        o_rd_tsc          ,      
        i_wr_tsc          ,      
        iv_raddr_tsc      ,          
        iv_rdata_tsc      ,      

        o_wr_cc          ,      
        ov_wdata_cc      ,      
        ov_addr_cc       ,         
        o_rd_cc          ,      
        i_wr_cc          ,      
        iv_raddr_cc      ,         
        iv_rdata_cc      ,  

        o_wr_ton          , 
        ov_wdata_ton      ,
        ov_addr_ton       ,
        o_rd_ton          ,
        i_wr_ton          ,
        iv_raddr_ton      ,
        iv_rdata_ton      ,

        ov_hcp_ext_command        ,
        o_hcp_ext_command_wr      ,        
        iv_hcp_ext_command_ack    ,
        i_hcp_ext_command_ack_wr  ,
        
        i_tsmp_lookup_table_key_wr        ,
        iv_tsmp_lookup_table_key          ,
        ov_tsmp_lookup_table_outport      ,
        o_tsmp_lookup_table_outport_wr    ,
        
	    i_gmii_rx_clk         ,
	    i_gmii_rx_dv          ,
        iv_gmii_rxd           ,
        i_gmii_rx_er          ,
	    o_gmii_tx_clk         ,
	    o_gmii_tx_en          , 
        ov_gmii_txd           ,
        o_gmii_tx_er          ,        
        
	    i_data_wr         ,
	    iv_data           ,  
	    ov_data           ,
	    o_data_wr                 
        
);
// I/O
// clk & rst
input               i_clk             ;
input               i_rst_n           ; 

input               i_sync_ok         ;     

output  [65:0]	    ov_hcp_ext_command        ;
output  	        o_hcp_ext_command_wr      ;
input   [65:0]	    iv_hcp_ext_command_ack    ;
input    	        i_hcp_ext_command_ack_wr  ;

input	  		    i_gmii_rx_clk         ;
input	  		    i_gmii_rx_dv          ;
input	[8:0]	 	iv_gmii_rxd           ;
input	  		    i_gmii_rx_er          ;
output      		o_gmii_tx_clk         ;
output      		o_gmii_tx_en          ; 
output  [8:0] 	  	ov_gmii_txd           ;
output      		o_gmii_tx_er          ;  

input	[8:0]	 	iv_data           ;
input	  		    i_data_wr         ;                                     
output  [8:0] 	  	ov_data           ;
output      		o_data_wr         ;

output  [11:0]      ov_local_id       ; 
input   [31:0]      iv_tss_ver        ;
output              o_rc_rxenable     ;
output              o_st_rxenable     ;
output              o_tsn_or_tte      ;

input   [31:0]      iv_master_port       ;
input   [31:0]      iv_port_ptp_enabled  ;

output              o_wr_tsc          ;        
output  [31:0]      ov_wdata_tsc      ;      
output  [18:0]      ov_addr_tsc       ;         
output              o_rd_tsc          ;      
input               i_wr_tsc          ;      
input   [18:0]      iv_raddr_tsc      ;          
input   [31:0]      iv_rdata_tsc      ; 

output              o_wr_cc          ;      
output  [31:0]      ov_wdata_cc      ;      
output  [18:0]      ov_addr_cc       ;       
output              o_rd_cc          ;      
input               i_wr_cc          ;      
input   [18:0]      iv_raddr_cc      ;         
input   [31:0]      iv_rdata_cc      ;      

output              o_wr_ton          ;      
output  [31:0]      ov_wdata_ton      ;      
output  [18:0]      ov_addr_ton       ;         
output              o_rd_ton          ;      
input               i_wr_ton          ;      
input   [18:0]      iv_raddr_ton      ;       
input   [31:0]      iv_rdata_ton      ; 

input               i_tsmp_lookup_table_key_wr       ;
input   [47:0]      iv_tsmp_lookup_table_key         ;
output  [32:0]      ov_tsmp_lookup_table_outport     ;
output              o_tsmp_lookup_table_outport_wr   ;      

wire                w_data_wr_rpr2hta    ;
wire    [7:0]       wv_data_rpr2hta      ;

wire                w_gmii_tx_en_ntx2gad ;
wire                w_gmii_tx_er_ntx2gad ;
wire    [7:0]       wv_gmii_txd_ntx2gad  ;
                
wire    [8:0]       wv_data_tpp2nma      ;
wire                w_data_wr_tpp2nma    ;
wire    [8:0]       wv_data_tpp2osp      ;
wire                w_data_wr_tpp2osp    ;
wire    [8:0]       wv_data_tpp2tfp      ;
wire                w_data_wr_tpp2tfp    ;
wire                w_encapsulated_flag_tpp2tfp;
wire    [8:0]       wv_data_tpp2adi      ;
wire                w_data_wr_tpp2adi    ;

wire    [8:0]       wv_data_hrx2tpp      ;
wire                w_data_wr_hrx2tpp    ;
//nma
wire    [65:0]	    wv_command_nma2lac      ;
wire  	            w_command_wr_nma2lac    ;                   
wire    [65:0]	    wv_command_ack_lac2nma  ;
wire   	            w_command_ack_wr_lac2nma;

wire                w_hrg_wr_lac2hrg    ;
wire    [31:0]      wv_hrg_wdata_lac2hrg;
wire    [18:0]      wv_hrg_addr_lac2hrg ;
wire                w_hrg_rd_lac2hrg      ;          
wire                w_hrg_wr_hrg2lac      ;
wire    [18:0]      wv_hrg_raddr_hrg2lac;
wire    [31:0]      wv_hrg_rdata_hrg2lac; 

wire    [18:0]      wv_addr_ta2tft    ;
wire    [31:0]      wv_wdata_ta2tft   ;
wire                w_wr_ta2tft       ;
wire                w_rd_ta2tft       ;
wire                w_wr_tft2ta       ;
wire    [18:0]      wv_raddr_tft2ta   ;
wire    [31:0]      wv_rdata_tft2ta   ; 

wire    [8:0]       wv_data_nma2ttc   ;
wire                w_data_wr_nma2ttc ;
wire    [8:0]       wv_data_osp2ttc   ;
wire                w_data_wr_osp2ttc ;
wire    [8:0]       wv_data_tfp2ttc   ;
wire                w_data_wr_tfp2ttc ;
wire    [8:0]       wv_data_pop2ttc   ;
wire                w_data_wr_pop2ttc ;

wire    [8:0]       wv_data_ttc2htx   ;
wire                w_data_wr_ttc2htx ;

//wire    [8:0]       wv_data_tan2ttc   ;
//wire                w_data_wr_tan2ttc ;

wire    [47:0]      wv_hcp_mac_hrg2other;
wire    [47:0]      wv_tsnlight_controller_mac_hrg2other;
//wire    [47:0]      wv_opensync_controller_mac_hrg2other;

wire    [11:0]      wv_hcp_mid_adi2hrg;
wire    [11:0]      wv_tsnlight_mid_adi2hrg;
assign  ov_local_id      =     wv_hcp_mid_adi2hrg;
assign  o_gmii_tx_clk    =     i_gmii_rx_clk       ;
assign  o_gmii_tx_en     =     i_gmii_rx_dv        ;
assign  ov_gmii_txd      =     iv_gmii_rxd         ;
assign  o_gmii_tx_er     =     i_gmii_rx_er        ;
hcp_register_group hcp_register_group_inst
(
.i_clk                           (i_clk                  ),
.i_rst_n                         (i_rst_n                ),
.iv_hcp_mid                      (wv_hcp_mid_adi2hrg     ),
.iv_tsnlight_mid                 (wv_tsnlight_mid_adi2hrg),
//.iv_os_cid                       (iv_os_cid              ),
.iv_tss_ver                      (iv_tss_ver             ),
.i_sync_ok                       (i_sync_ok              ),
.o_rc_rxenable                   (o_rc_rxenable          ),
.o_st_rxenable                   (o_st_rxenable          ),
.o_tsn_or_tte                    (o_tsn_or_tte           ),
.iv_addr                         (wv_hrg_addr_lac2hrg    ),                
.iv_wdata                        (wv_hrg_wdata_lac2hrg   ),          
.i_wr                            (w_hrg_wr_lac2hrg       ),           
.i_rd                            (w_hrg_rd_lac2hrg       ),           
.o_wr                            (w_hrg_wr_hrg2lac       ),           
.ov_addr                         (wv_hrg_raddr_hrg2lac   ),           
.ov_rdata                        (wv_hrg_rdata_hrg2lac   ),  
                                 
.ov_hcp_mac                      (wv_hcp_mac_hrg2other   ) ,
.ov_tsnlight_controller_mac      (wv_tsnlight_controller_mac_hrg2other)     
);

tsmp_protocol_process tsmp_protocol_process_inst
(
.i_clk                  (i_clk                  ),
.i_rst_n                (i_rst_n                ),
                                                
.iv_data                (iv_data    ),//(wv_data_hrx2tpp        ),
.i_data_wr              (i_data_wr  ),//(w_data_wr_hrx2tpp      ),
                                                
.ov_data_nma            (wv_data_tpp2nma        ),
.o_data_wr_nma          (w_data_wr_tpp2nma      ),
                                                
.ov_data_osp            (wv_data_tpp2osp        ),
.o_data_wr_osp          (w_data_wr_tpp2osp      ),
                                                
.ov_data_tfp            (wv_data_tpp2tfp        ),
.o_data_wr_tfp          (w_data_wr_tpp2tfp      ),
.o_encapsulated_flag_tfp(w_encapsulated_flag_tpp2tfp),

.ov_data_adi            (wv_data_tpp2adi        ),
.o_data_wr_adi          (w_data_wr_tpp2adi      )
);

network_management network_management_inst
(
.i_clk              (i_clk                    ),
.i_rst_n            (i_rst_n                  ),
                                              
.ov_command         (wv_command_nma2lac       ),
.o_command_wr       (w_command_wr_nma2lac     ),                                                    
.iv_command_ack     (wv_command_ack_lac2nma   ),
.i_command_ack_wr   (w_command_ack_wr_lac2nma ),
                                              
.iv_hcp_mac         (wv_hcp_mac_hrg2other     ),
.iv_controller_mac  (wv_tsnlight_controller_mac_hrg2other),       

.iv_data            (wv_data_tpp2nma          ),
.i_data_wr          (w_data_wr_tpp2nma        ),

.ov_data            (wv_data_nma2ttc  ),
.o_data_wr          (w_data_wr_nma2ttc)
);

local_access_control local_access_control_inst
(
.i_clk                   (i_clk   ),
.i_rst_n                 (i_rst_n ),       
                         
.iv_command              (wv_command_nma2lac      ),
.i_command_wr            (w_command_wr_nma2lac    ),        
.ov_command_ack          (wv_command_ack_lac2nma  ),
.o_command_ack_wr        (w_command_ack_wr_lac2nma),
                         
.o_hrg_wr                (w_hrg_wr_lac2hrg        ),
.ov_hrg_wdata            (wv_hrg_wdata_lac2hrg    ),
.ov_hrg_addr             (wv_hrg_addr_lac2hrg     ),
.o_hrg_rd                (w_hrg_rd_lac2hrg        ),       
.i_hrg_wr                (w_hrg_wr_hrg2lac        ),
.iv_hrg_raddr            (wv_hrg_raddr_hrg2lac    ),
.iv_hrg_rdata            (wv_hrg_rdata_hrg2lac    ),

.o_tan_wr                (o_wr_ton        ),      
.ov_tan_wdata            (ov_wdata_ton    ),  
.ov_tan_addr             (ov_addr_ton     ),   
.o_tan_rd                (o_rd_ton        ),            
.i_tan_wr                (i_wr_ton        ),      
.iv_tan_raddr            (iv_raddr_ton    ),  
.iv_tan_rdata            (iv_rdata_ton    ),  

.o_ost_wr                (o_wr_tsc                ),
.ov_ost_wdata            (ov_wdata_tsc            ),
.ov_ost_addr             (ov_addr_tsc             ),
.o_ost_rd                (o_rd_tsc                ),       
.i_ost_wr                (i_wr_tsc                ),
.iv_ost_raddr            (iv_raddr_tsc            ),
.iv_ost_rdata            (iv_rdata_tsc            ),

.o_cc_wr                 (o_wr_cc                ),
.ov_cc_wdata             (ov_wdata_cc            ),
.ov_cc_addr              (ov_addr_cc             ),
.o_cc_rd                 (o_rd_cc                ),       
.i_cc_wr                 (i_wr_cc                ),
.iv_cc_raddr             (iv_raddr_cc            ),
.iv_cc_rdata             (iv_rdata_cc            ),

.o_tft_wr                (w_wr_ta2tft                  ),
.ov_tft_wdata            (wv_wdata_ta2tft              ),
.ov_tft_addr             (wv_addr_ta2tft               ),
.o_tft_rd                (w_rd_ta2tft                  ),       
.i_tft_wr                (w_wr_tft2ta                  ),
.iv_tft_raddr            (wv_raddr_tft2ta              ),
.iv_tft_rdata            (wv_rdata_tft2ta              ),
                         
.ov_hcp_ext_command      (ov_hcp_ext_command           ),
.o_hcp_ext_command_wr    (o_hcp_ext_command_wr         ),
.iv_hcp_ext_command_ack  (iv_hcp_ext_command_ack       ),
.i_hcp_ext_command_ack_wr(i_hcp_ext_command_ack_wr     )				     
);

tunnel_frame_process tunnel_frame_process_inst
(
.i_clk               (i_clk                      ),
.i_rst_n             (i_rst_n                    ),

.i_rc_rxenable       (o_rc_rxenable              ),

.iv_hcp_mac          (wv_hcp_mac_hrg2other       ),
.iv_controller_mac   (wv_tsnlight_controller_mac_hrg2other),

.iv_data             (wv_data_tpp2tfp            ),
.i_data_wr           (w_data_wr_tpp2tfp          ),
.i_encapsulated_flag (w_encapsulated_flag_tpp2tfp),
                                               
.ov_data             (wv_data_tfp2ttc          ),
.o_data_wr           (w_data_wr_tfp2ttc        )   
);

address_dispatch address_dispatch_inst
(
.i_clk       (i_clk             ),
.i_rst_n     (i_rst_n           ),

.iv_data     (wv_data_tpp2adi   ),
.i_data_wr   (w_data_wr_tpp2adi ),

.ov_hcp_mid  (wv_hcp_mid_adi2hrg),
.ov_tsnlight_mid(wv_tsnlight_mid_adi2hrg)
);

mux_5to1 tsmp_transmit_control_inst
(
.i_clk        (i_clk   ),
.i_rst_n      (i_rst_n ),
        
.iv_data_1    (wv_data_nma2ttc   ),
.i_data_wr_1  (w_data_wr_nma2ttc ),
                
.iv_data_2    (9'b0   ),
.i_data_wr_2  (1'b0   ),
              
.iv_data_3    (wv_data_tfp2ttc   ),
.i_data_wr_3  (w_data_wr_tfp2ttc ),
              
.iv_data_4    (9'b0),//(wv_data_tan2ttc   ),
.i_data_wr_4  (1'b0),//(w_data_wr_tan2ttc ),
              
.iv_data_5    (9'b0 ),
.i_data_wr_5  (1'b0 ),
     
.ov_data      (ov_data  ),//(wv_data_ttc2htx   ),
.o_data_wr    (o_data_wr),//(w_data_wr_ttc2htx ),

.ov_discard_pkt_cnt_fop_1(),
.ov_cut_pkt_cnt_fop_1    (),
.ov_discard_pkt_cnt_fop_2(),
.ov_cut_pkt_cnt_fop_2    (),
.ov_discard_pkt_cnt_fop_3(),
.ov_cut_pkt_cnt_fop_3    (),
.ov_discard_pkt_cnt_fop_4(),
.ov_cut_pkt_cnt_fop_4    (),
.ov_discard_pkt_cnt_fop_5(),
.ov_cut_pkt_cnt_fop_5    ()
);

tsmp_forward_table tsmp_forward_table_inst
(
.i_clk                            (i_clk                            ),
.i_rst_n                          (i_rst_n                          ),

.iv_hcp_mid                       (wv_hcp_mid_adi2hrg                      ),
.iv_master_port                   (iv_master_port           ),
.iv_port_ptp_enabled              (iv_port_ptp_enabled      ),
 
.iv_addr                          (wv_addr_ta2tft                   ), 
.iv_wdata                         (wv_wdata_ta2tft                  ),  
.i_wr                             (w_wr_ta2tft                      ), 
.i_rd                             (w_rd_ta2tft                      ),                
.o_wr                             (w_wr_tft2ta                      ), 
.ov_addr                          (wv_raddr_tft2ta                  ), 
.ov_rdata                         (wv_rdata_tft2ta                  ), 

.i_tsmp_lookup_table_key_wr       (i_tsmp_lookup_table_key_wr       ),
.iv_tsmp_lookup_table_key         (iv_tsmp_lookup_table_key         ),
.ov_tsmp_lookup_table_outport     (ov_tsmp_lookup_table_outport     ),
.o_tsmp_lookup_table_outport_wr   (o_tsmp_lookup_table_outport_wr   )	   
);
endmodule 